document.addEventListener('DOMContentLoaded', function () {
    var href = document.location.href;
    if(href.length<22){
        return false;
    }
    if (href != "" && href.substr(0, 22) == "https://www.baidu.com/") {
        console.info("dasdas");
        var searchParam = href.substr(href.indexOf("?") + 1);
        var searchParams = searchParam.split("&");
        $("a").each(function () {
            var that = this;
            var aHref = $(that).attr("href");
            if (typeof(aHref) == "string" && (aHref.indexOf("https://www.baidu.com/s") != -1 || aHref.indexOf("/s?") != -1)) {
                var aHrefParam = aHref.substr(href.indexOf("?") + 1);
                var aHrefParams = aHrefParam.split("&");
                $.each(aHrefParams, function (i, val) {
                    if (val.split("=")[0] == "wd") {
                        if (val.split("=")[1].indexOf("-baijiahao") == -1 || ("" != val.split("=")[1] && val.split("=")[1].substr(val.split("=")[1].length - "-baijiahao".length) != "-baijiahao")) {
                            var newValue = val.split("=")[1] + " -baijiahao";
                            href = aHref.replace(val, "wd=" + newValue);
                            $(that).attr("href", href);
                        }
                    }
                })
            }
        });
        $(document).on("click", "#su", function () {
            var oldVal = $("input[name=wd]").val();
            if (oldVal.indexOf("-baijiahao") == -1 || ("" != oldVal && oldVal.substr(oldVal.length - "-baijiahao".length) != "-baijiahao")) {
                $("input[name=wd]").val(oldVal + " -baijiahao");
            }
        })

        $.each(searchParams, function (i, val) {
            if (val.split("=")[0] == "wd") {
                if (val.split("=")[1].indexOf("-baijiahao") == -1 || ("" != val.split("=")[1] && val.split("=")[1].substr(val.split("=")[1].length - "-baijiahao".length) != "-baijiahao")) {
                   $("#su").click();
                }
            }
        })

    }

})

